package com.stormrage.edu.ctrl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.stormrage.entity.shiro.ShiroAcct;
import com.stormrage.shiro.bind.CurrentUser;
import com.stormragetech.core.ctrl.BaseCtrl;

/**
 * @author www.stormragetech.com
 * @date 2016年3月10日
 * @version 1.0.0
 */
@Controller
public class IndexCtrl extends BaseCtrl {

	private static final Logger logger = LoggerFactory.getLogger(IndexCtrl.class);

	@Value("#{constants['html.title']}")
	private String htmlTitle;

	@Value("#{constants['html.logo']}")
	private String htmlLogo;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index(@CurrentUser ShiroAcct curr, Model model) {

		logger.debug(" 【 CONTROLLER 】- 【 INDEX 】- 开始运行 ");

		logger.debug(" Constants的字符串为 " + htmlTitle + " | " + htmlLogo);

		try {

			// ------------------ 获取用户操作的 Menu ------------------
			model.addAttribute("user", curr);
			model.addAttribute("htmltitle", htmlTitle);
			model.addAttribute("htmllogo", htmlLogo);

		} catch (Exception e) {
			model.addAttribute("err", e.getMessage());
			return "error/500";
		}

		return "index";
	}

	@RequestMapping(value = "/result", method = RequestMethod.GET)
	public String result(Model model) {

		logger.debug(" 【 CONTROLLER 】- 【 INDEX 】- 开始运行 ");

		logger.debug(" Constants的字符串为 " + htmlTitle + " | " + htmlLogo);

		try {

			// ------------------ 获取用户操作的 Menu ------------------
			model.addAttribute("htmltitle", htmlTitle);
			model.addAttribute("htmllogo", htmlLogo);
			
		} catch (Exception e) {
			model.addAttribute("err", e.getMessage());
			return "error/500";
		}

		return "result";
	}

}
